Introduction to Game Physics With Box2D by Ian Parberry
Author:Ian Parberry
Language: eng
Format: mobi, epub
Tags: Games, Computers, Programming, Video & Animation, Digital Media
ISBN: 9781466565760
Publisher: CRC Press
Published: 2013-02-06T00:00:00+00:00
5.4 • Our First Box2D App
127
Descending from the highest level of the code in MyGame.cpp to the
lowest level of the code for the lowly Game Object, we see in object.h
that CGameObject retains only its m_nObjectType member variable and
its constructor and destructor. Everything else has vanished. In return,
it gets a b2Body pointer m_pBody and a SetPhysicsBody function that
should be familiar from the description of function CreateBook a couple of
paragraphs ago. The latter function sets the former member variable to the
value of its parameter. Object.cpp should once again hold no surprises
for you, with the one obvious exception being that its destructor calls
g_b2dPhysicsWorld’s DestroyBody function to release the Physics body
pointed to by m_pBody.
C G a m e O b j e c t ::~ C G a m e O b j e c t (){
if ( m _ p B o d y )
g _ b 2 d P h y s i c s W o r l d . D e s t r o y B o d y ( m _ p B o d y );
} // d e s t r u c t o r
Moving up a level from the Game Object to the Object Manager, we
see in ObjectManager.cpp that CObjectManager’s draw function used to
have code to get the object’s position from the Game Object directly like
this:
if ( p ){
D 3 D X V E C T O R 2
v = p - > m _ v P o s i t i o n ;
g _ c R e n d e r W o r l d . draw ( p - > m _ n O b j e c t T y p e , v . x , v . y );
} // if
Now, it has to get the object’s position and orientation from the Physics
World instead, as follows:
if ( p ){
f l o a t a = p - > m_pBody - > G e t A n g l e ();
b 2 V e c 2 v = p - > m_pBody - > G e t P o s i t i o n ();
g _ c R e n d e r W o r l d . draw ( p - > m _ n O b j e c t T y p e ,
P W 2 R W ( v . x ) , P W 2 R W ( v . y ) , a );
} // if
The Object Manager’s move function is now only a single line of code.
Instead of doing any kind of physics calculations itself, it asks the Physics
World to perform a simulation step for it. What could be easier?
void
C O b j e c t M a n a g e r :: move (){
g _ b 2 d P h y s i c s W o r l d . Step (1.0 f / 6 0 . 0 f , 6 , 2);
} // move
Download
Introduction to Game Physics With Box2D by Ian Parberry.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Personalized inhaled bacteriophage therapy for treatment of multidrug-resistant Pseudomonas aeruginosa in cystic fibrosis by unknow(157790)
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(74285)
CONSORT 2025 statement: updated guideline for reporting randomized trials by unknow(66087)
Critical evaluation of the ProfiLER-02 study design and outcomes by Vivek Subbiah & Razelle Kurzrock(65835)
Cardiac gene therapy makes a comeback by Oliver J. Müller & Susanne Hille & Anca Kliesow Remes(65273)
Unveiling the design rules for tunable emission in graphene quantum dots: A high-throughput TDDFT and machine learning perspective by Şener Özönder & Mustafa Coşkun Özdemir & Caner Ünlü(50860)
A yeast-based oral therapeutic delivers immune checkpoint inhibitors to reduce intestinal tumor burden by unknow(40229)
Covalent hitchhikers guide proteins to the nucleus by Alexander F. Russell & Madeline F. Currie & Champak Chatterjee(40194)
Meet the Authors: Christopher R. Mansfield and Emily R. Derbyshire by Christopher R. Mansfield & Emily R. Derbyshire(40058)
What's Done in Darkness by Kayla Perrin(27113)
Topological analysis of non-conjugated ethylene oxide cored dendrimers decorated with tetraphenylethylene: Insights from degree-based descriptors using the polynomial approach by A Theertha Nair & D Antony Xavier & Annmaria Baby & S Akhila(26486)
Investigation of mechanical and self-healing properties of hydroxyl-terminated polybutadiene functionalized with 2-ureido-4-pyrimidinone by Mohsen Kazazi & Mehran Hayaty & Ali Mousaviazar(26437)
The Ultimate Python Exercise Book: 700 Practical Exercises for Beginners with Quiz Questions by Copy(21027)
De Souza H. Master the Age of Artificial Intelligences. The Basic Guide...2024 by Unknown(20782)
D:\Jan\FTP\HOL\Work\Alien Breed - Tower Assault CD32 Alien Breed II - The Horror Continues Manual 1.jpg by PDFCreator(20653)
The Fifty Shades Trilogy & Grey by E L James(19609)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19488)
Shot Through the Heart by Mercy Celeste(19351)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(17497)